package main

import (
	"errors"
	"fmt"
)

func main() {
	var acc Account = Account{No: "1234646", Password: "123456", Balance: 80000}
	left, err := (&acc).queryMoney("123456")
	if err != nil {
		fmt.Println("ERROR=", err)
	} else {
		fmt.Println("余额=", left)
	}
}

type Account struct {
	No       string
	Password string
	Balance  float64
}

// Deposit
//
//	@Description: 存
//	@receiver a
//	@param money
//	@param pwd
func (a *Account) Deposit(money float64, pwd string) {
	if pwd != (*a).Password {
		fmt.Println("密码错误")
		return
	}
	if money < 0 {
		fmt.Println("输入金额不能小于0")
		return
	}
	(*a).Balance += money
	fmt.Println("Success")
}

// getMoney
//
//	@Description: 取
//	@receiver a
//	@param money
//	@param pwd
func (a *Account) getMoney(money float64, pwd string) {
	if pwd != (*a).Password {
		fmt.Println("密码错误")
		return
	}
	if money <= 0 {
		fmt.Println("输入金额不能小于0")
		return
	}
	if (*a).Balance < money {
		fmt.Println("余额不足")
		return
	}
	(*a).Balance -= money
	fmt.Println("Success")
}

// queryMoney
//
//	@Description: 查询
//	@receiver a
//	@param pwd
//	@return left
//	@return err
func (a *Account) queryMoney(pwd string) (left float64, err error) {
	if pwd != (*a).Password {
		return 0, errors.New("密码错误")
	}

	return (*a).Balance, nil
}
